<template>
  <el-table
    ref="filterTable"
    :data="tableData"
    style="width: 100%"
    @selection-change="handleSelectionChange"
    @row-click="handleRowClick"
    >>
    <el-table-column prop="code" label="编号" sortable> </el-table-column>
    <el-table-column
      prop="name"
      label="名称"
      sortable
      column-key="name"
      :filters="getFilters('name')"
      :filter-method="filterHandler"
    >
    </el-table-column>
    <el-table-column prop="status" label="状态"> </el-table-column>
    <el-table-column prop="date" label="创建时间"> </el-table-column>
  </el-table>
</template>

<script>
export default {
  props: { 
      tableData: {
          type: Array,
          default: []
      }
  },
  data() {
    return {
      multipleSelection: [],
    };
  },
  methods: {
    resetNameFilter() {
      this.$refs.filterTable.clearFilter("name");
    },
    clearFilter() {
      this.$refs.filterTable.clearFilter();
    },
    formatter(row, column) {
      return row.address;
    },
    filterTag(value, row) {
      return row.tag === value;
    },
    filterHandler(value, row, column) {
      const property = column["property"];
      return row[property] === value;
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
      this.tableData.splice(index, 1);
    },
    deleteRows() {
      for (let i of this.multipleSelection) {
        for (let j in this.tableData) {
          if (i.code == this.tableData[j].code) {
            this.tableData.splice(j, 1);
          }
        }
      }
    },
    getFilters(key) {
      let arr = [];
      for (let i of this.tableData) {
        arr.push({
          text: i[key],
          value: i[key],
        });
      }
      return arr;
    },
    handleRowClick(row, column, event) {
      // console.log(row,column)
      this.$router.push({
        path: "/clients/details",
        // name: 'mallList',
        query: {
          code: row.code,
        },
      });
    },
  },
};
</script>

<style>
</style>